<?php

?>

<?php
foreach ($items as $item) {
    ?>
    <div class="panel">
        <!--    <div class="panel-heading">xx机构订单</div>-->
        <div class="panel-body">
            <div class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-2 form-label-key">下单用户:</label>
                    <label class="col-sm-4 form-label-value"><?= $item['user_name'] ?></label>
                    <label class="col-sm-2 form-label-key">所属机构:</label>
                    <label class="col-sm-4 form-label-value"><?= $item['institution_name'] ?></label>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 form-label-key">订单销售价:</label>
                    <label class="col-sm-4 form-label-value">￥<?= $item['total_selling_price'] ?></label>
                    <label class="col-sm-2 form-label-key">订单结算价:</label>
                    <label class="col-sm-4 form-label-value">￥<?= $item['total_settlement_price'] ?></label>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 form-label-key">订单状态:</label>
                    <div class="col-sm-4">
                        <label class="form-label-value"><?= $item['status_name'] ?></label>
                        <?php
                        switch ($item['status']) {
                            case 10:  // 待审核订单
                                echo " <a class=' btn btn-primary' id='btnApproveOrderFlow' data-id='{$item['id']}' data-code='{$item['order_code']}'>订单审核</a>";
                                break;
                            case 11:  // 待结算订单
                            case 12:  // 未结算订单
                                echo " <a class=' btn btn-primary' id='btnPayOrderFlow' data-id='{$item['id']}' data-code='{$item['order_code']}'>订单结算</a>";
                                break;
                            case 13:  // 支付成功订单
                                echo " <a class=' btn btn-primary' id='btnAddOrderFlow' data-id='{$item['id']}' data-code='{$item['order_code']}'>订单提交</a>";
                                break;
                        }
                        ?>
                    </div>
                    <label class="col-sm-2 form-label-key">下单时间:</label>
                    <label class="col-sm-4 form-label-value"><?= $item['create_datetime'] ?></label>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 form-label-key">备注:</label>
                    <label class="col-sm-10 form-label-value"><?= $item['remark'] ?></label>
                </div>
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-condensed">
                        <thead class="nowrap">
                        <tr>
                            <th>商品编号</th>
                            <th>商品名称</th>
                            <th>销售价</th>
                            <th>结算价</th>
                            <th>数量</th>
                            <th>销售金额</th>
                            <th>结算金额</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        foreach ($item['goods_list'] as $goodsItem) {
                            ?>
                            <tr>
                                <td><?= $goodsItem['goods_code'] ?></td>
                                <td><?= $goodsItem['goods_name'] ?></td>
                                <td><?= $goodsItem['selling_price'] ?></td>
                                <td><?= $goodsItem['settlement_price'] ?></td>
                                <td><?= $goodsItem['quantity'] ?></td>
                                <td>￥<?= $goodsItem['selling_price']*$goodsItem['quantity'] ?></td>
                                <td>￥<?= $goodsItem['settlement_price']*$goodsItem['quantity'] ?></td>
                            </tr>
                            <?php
                        }
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <?php
}
?>

<script type="application/javascript">
    $(function () {
        $('#btnApproveOrderFlow').click(function () {
            var data = {};
            data.order_flow_id = $(this).attr('data-id');
            data.order_code = $(this).attr('data-code');
            loading.show();
            requestJson('approve-order-flow-handler', data, true, function (responseData) {
                loadOrderFlowListPartView(responseData.data);
                loading.hide();
            });
        });

        $('#btnPayOrderFlow').click(function () {
            var data = {};
            data.order_flow_id = $(this).attr('data-id');
            data.order_code = $(this).attr('data-code');
            loading.show();
            requestJson('pay-order-flow-handler', data, true, function (responseData) {
                if (responseData.status == 0) {
                    loadOrderFlowListPartView(responseData.data);
                } else {
                    alert(responseData.message);
                }
                loading.hide();
            });
        });

        $('#btnAddOrderFlow').click(function () {
            var data = {};
            data.order_flow_id = $(this).attr('data-id');
            data.order_code = $(this).attr('data-code');
            loading.show();
            requestJson('add-order-flow-handler', data, true, function (responseData) {
                if (responseData.status == 0) {
                    loadOrderFlowListPartial(responseData.data);
                } else {
                    alert(responseData.message);
                }
                loading.hide();
            });
        });
    });
</script>
